/*
* © 2010 Autodata Solutions Company. All Rights Reserved
* This source code is the confidential and proprietary information of Autodata Solutions Company.
* The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
* without the prior written consent of Autodata Solutions Company.
*/
Ext.ns('net.autodata.compare.photos');
(function () {
	
	var DQ = Ext.DomQuery;
	
	/**
	 * @class VehiclePanel
	 * @extends Ext.BoxComponent
	 * @namespace net.autodata.compare.photos
	 */
	var Panel = Ext.extend(Ext.BoxComponent, {
		
		autoEl: {
			tag: 'div',
			cls: 'vehiclephoto-panel'
		},
		
		iofImage: undefined,
		
		iofImageCfg: {
			imageWidth: 194,
			imageHeight: 95
		},
		
		constructor: function ()
		{
			this.addEvents({'click': true});
			Panel.superclass.constructor.apply(this, arguments);
		},
		
		initComponent: function ()
		{
			Panel.superclass.initComponent.apply(this, arguments);
			var view = this.getView();
			view.init(this);
			
			this.iofImage = new net.autodata.IOFImage(this.iofImageCfg);
		},
		
		getView: function ()
		{
			if (!this.view) {
				this.view = new net.autodata.compare.photos.VehiclePhotoView(this.viewCfg);
			}
			return this.view;
		},
		
		setIOFImageName: function (imageName)
		{
			if (!Ext.isEmpty(imageName)) {
				this.iofImage.setImageName(imageName);
			} else {
				this.iofImage.setImageName(this.iofImage.errorImageName);
			}
		},
		
		/**
		 * @private
		 */
		onRender: function ()
		{
			Panel.superclass.onRender.apply(this, arguments);
			
			this.el.on('click', this.onClick, this);
			
			var view = this.getView();
			view.render();
		},
		
		onEnable: function ()
		{
			Panel.superclass.onEnable.apply(this, arguments);
			this.toggleViewLarger(true);
		},
		
		onDisable: function ()
		{
			Panel.superclass.onDisable.apply(this, arguments);
			this.toggleViewLarger(false);
		},
		
		/**
		 * @private
		 */
		toggleViewLarger: function (show)
		{
			var dom = this.el.dom;
			Ext.fly(DQ.selectNode('.view-larger', dom)).setVisible(show);
		},
		
		/**
		 * @private
		 */
		onClick: function (e)
		{
			if (e) {
        		e.preventDefault();
        	}
        	
			if(e.button !== 0 || this.disabled){
	            return;
	        }
			
        	this.fireEvent('click', this, e);
        	if (this.handler) {
        		this.handler.call(this.scope || this, this, e);
        	} 
		},
		
		/**
		 * @private
		 */
		onDestroy: function ()
		{
			this.el.un('click', this.onClick, this);
			Panel.superclass.onDestroy.apply(this, arguments);
		}
		
	});
	
	net.autodata.compare.photos.VehiclePhotoPanel = Panel;
	
})();